import {createRouter, createWebHistory} from "vue-router"

const routerHistory = createWebHistory()

const childrenRoutes = [
    {
        path: 'home',
        name: 'home',
        meta: {
            auth: true,
            title: '首页',
            icon: 'user'
        },
        component: () => import('@/views/home/Home')
    },
    {
        path: 'aes',
        name: 'aes',
        meta: {
            auth: true,
            title: 'AES算法',
            icon: 'user'
        },
        component: () => import('@/views/aes/AES')
    },
    {
        path: 'des',
        name: 'des',
        meta: {
            auth: true,
            title: 'DES算法',
            icon: 'user'
        },
        component: () => import('@/views/des/DES')
    },
    /*{
        path: 'dsa',
        name: 'dsa',
        meta: {
            auth: true,
            title: 'DSA算法',
            icon: 'user'
        },
        component: () => import('@/views/dsa/DSA')
    },*/
    /*{
        path: 'ecdsa',
        name: 'ecdsa',
        meta: {
            auth: true,
            title: 'ECDSA算法',
            icon: 'user'
        },
        component: () => import('@/views/ecdsa/ECDSA')
    },*/
    {
        path: 'hmac',
        name: 'hmac',
        meta: {
            auth: true,
            title: 'HMAC算法',
            icon: 'user'
        },
        component: () => import('@/views/hmac/HMAC')
    },
    {
        path: 'md5',
        name: 'md5',
        meta: {
            auth: true,
            title: 'MD5算法',
            icon: 'user'
        },
        component: () => import('@/views/md5/MD5')
    },
    {
        path: 'rc4',
        name: 'rc4',
        meta: {
            auth: true,
            title: 'RC4算法',
            icon: 'user'
        },
        component: () => import('@/views/rc4/RC4')
    },
    {
        path: 'rsa',
        name: 'rsa',
        meta: {
            auth: true,
            title: 'RSA算法',
            icon: 'user'
        },
        component: () => import('@/views/rsa/RSA')
    },
    {
        path: 'sha1',
        name: 'sha1',
        meta: {
            auth: true,
            title: 'SHA1算法',
            icon: 'user'
        },
        component: () => import('@/views/sha1/SHA1')
    },
    {
        path: 'sha256',
        name: 'sha256',
        meta: {
            auth: true,
            title: 'SHA256算法',
            icon: 'user'
        },
        component: () => import('@/views/sha256/SHA256')
    },
    {
        path: 'sha512',
        name: 'sha512',
        meta: {
            auth: true,
            title: 'SHA512算法',
            icon: 'user'
        },
        component: () => import('@/views/sha512/SHA512')
    },
    {
        path: 'other',
        name: 'other',
        meta: {
            auth: true,
            title: '乱七八糟',
            icon: 'user'
        },
        component: () => import('@/views/other/Other')
    },
]

const router = createRouter({
    // 设置路由为history模式
    history: routerHistory,
    routes: [
        {
            path: '/',
            name: 'index',
            meta: {
                auth: true
            },
            component: () => import('@/components/layout/Layout.vue'),
            children: childrenRoutes
        }
    ]
})

// 路由跳转鉴权
/*Router.beforeEach((to, from, next) => {

    const isLogin = localStorage.getItem("isLogin") || null

    if (to.meta.auth) {
        if (isLogin) {
            next()
        } else {
            next({
                path: '/login'
            })
        }
    } else {
        next()
    }

    if (to.fullPath === '/login') {
        if (isLogin) {
            next({
                path: from.fullPath
            })
        } else {
            next()
        }
    }
})*/

export default router
